package com.lyy;

import com.rabbitmq.client.*;

public class consumer {
    //队列名称
    public static final String QUEUE_NAME="hello";

    public static void main(String[] args) throws Exception {
        ConnectionFactory factory=new ConnectionFactory();
        factory.setHost("39.105.129.255");
        factory.setUsername("admin");
        factory.setPassword("123");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        /**
         * 消费者消费消息
         * 消费哪个队列
         * 消费成功后是否要自动应答true代表自动应答 fase代表手动应答
         * 消费者未成功消费的一个回调
         * 消费者取消消费的一个回调
         *
         *
         */
        //声明接受消息
        DeliverCallback deliverCallback=(consumerTag,message)->{
            System.out.println(new String(message.getBody()));

        };

        //取消消息
        CancelCallback cancelCallback=consumerTag->{
            System.out.println("消息消费被中断");
        };

        channel.basicConsume(QUEUE_NAME,true,deliverCallback,cancelCallback);
    }
}
